package modelLayer;

import java.util.ArrayList;

public class CustomerContainer {
   private ArrayList<Customer> customers;
   private static CustomerContainer instance;
   
   private CustomerContainer() {
       customers = new ArrayList<>();
    }
    
   public static CustomerContainer getInstance() {
       if(instance == null) {
           instance = new CustomerContainer();
        }
        
       return instance;
    }
    
   public void addCustomer(Customer cust) {
        customers.add(cust);
    }
   
   public Customer findCustomer(int ccpr) {
       boolean found = false;
       int index = 0;
       while(index < customers.size() && !found) {
           Customer cust = customers.get(index);
           if(cust.getCpr() == ccpr) {
               found = true;
            }
            else {
                index++;
            }
        }
        
        if(found) {
            return customers.get(index);
        }
        else {
            return null;
        }
    }
    
   public void removeCustomer(Customer cust) {
       customers.remove(cust);
   }
    
   public int numberOfCustomer() {
       return customers.size();
    }
}
